package com.mengxiangnongfu.controller.system;

import com.mengxiangnongfu.dto.LoginInfoDto;
import com.mengxiangnongfu.service.LoginInfoService;
import com.mengxiangnongfu.vo.AjaxResult;
import com.mengxiangnongfu.vo.DataGridView;
import io.swagger.annotations.Api;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 操作日志
 *
 * @author Yang
 * @version 1.0
 * @date 2020/10/3 14:58
 */
@Log4j2
@RestController
@RequestMapping("/system/loginlog")
@Api(value = "登录日志管理")
public class LoginInfoController {

    @Resource
    private LoginInfoService loginInfoService;

    /***
     * @Description: 分页查询登录日志
     * @Param: [loginInfoDto]
     * @return: com.mengxiangnongfu.vo.AjaxResult
     * @Author: Yang
     * @Date: 2020/10/24 - 20:56
     */
    @GetMapping(value = "loadAllLoginLogsByPage")
    public AjaxResult loadAllLoginLogsByPage(LoginInfoDto loginInfoDto) {
        DataGridView dataGridView = loginInfoService.loadAllLoginInfoLog(loginInfoDto);
        return AjaxResult.success("查询成功", dataGridView.getDataList(), dataGridView.getTotalCount());
    }

    /***
     * @Description: 删除登录日志
     * @Param: [ids]
     * @return: com.mengxiangnongfu.vo.AjaxResult
     * @Author: Yang
     * @Date: 2020/10/24 - 20:57
     */
    @DeleteMapping("removeLoginLogByIds/{ids}")
    public AjaxResult removeLoginLogByIds(@PathVariable Long[] ids) {
        log.info("批量删除登录日志");
        return AjaxResult.toAjax(loginInfoService.removeLoginInfoLog(ids));
    }

    /***
     * @Description: 删除全部登录日志
     * @Param: []
     * @return: com.mengxiangnongfu.vo.AjaxResult
     * @Author: Yang
     * @Date: 2020/10/24 - 20:57
     */
    @DeleteMapping("clearAllLoginLogs")
    public AjaxResult clearAllLoginLog() {
        return AjaxResult.toAjax(loginInfoService.clearAllLoginLog());
    }

}
